package com.zoffy.wmsbackend.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zoffy.wmsbackend.common.BaseResponse;
import com.zoffy.wmsbackend.common.CommonObj;
import com.zoffy.wmsbackend.common.RequestParam;
import com.zoffy.wmsbackend.common.ResultUtils;
import com.zoffy.wmsbackend.model.dto.stockOut.StockOutOrderDto;
import com.zoffy.wmsbackend.model.dto.stockOut.StockOutDTO;
import com.zoffy.wmsbackend.model.vo.stock.stockOut.StockOutOrderDetailsVo;
import com.zoffy.wmsbackend.model.vo.stock.stockOut.StockOutOrderVo;
import com.zoffy.wmsbackend.service.StockOutOrderService;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@PreAuthorize("hasAuthority('admin')")
@RequestMapping("/stockOut")
public class StockOutController {
    @Resource
    private StockOutOrderService stockOutOrderService;
    @PostMapping("/list")
    public BaseResponse<Page<StockOutOrderVo>> listStockOutOrderByPage(@RequestBody RequestParam<StockOutOrderDto> requestParam){
        Page<StockOutOrderVo> res = stockOutOrderService.listStockOutOrderVoByPage(requestParam);
        return ResultUtils.success(res);
    }
    @PostMapping("/add")
    public BaseResponse<Boolean> addStockOutOrder(@RequestBody StockOutDTO stockOutDTO){
        Boolean res = stockOutOrderService.stockOut(stockOutDTO);
        return ResultUtils.success(res);
    }
    @PostMapping("/approval")
    public BaseResponse<Boolean> approval(@RequestBody CommonObj<Long> stockOutId){
        Long id = stockOutId.getData();
        Boolean res = stockOutOrderService.approval(id);
        return ResultUtils.success(res);
    }
    @GetMapping("/")
    public BaseResponse<StockOutOrderDetailsVo> getDetailsById(@org.springframework.web.bind.annotation.RequestParam("id") Long id){
        StockOutOrderDetailsVo res = stockOutOrderService.getDetailsById(id);
        return ResultUtils.success(res);
    }
}
